<template>
  <el-dialog title="角色分配" :visible.sync="isShow" @close="closeEvent">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUserGit, sysUserAssignRoles } from '@/api/employess.js'
export default {
  name: 'DialogRole',
  data() {
    return {
      isShow: false,
      checkList: [],
      list: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    closeEvent() {
      this.isShow = false
    },
    async getData() {
      const res = await sysRole({ pagesize: 100 })
      this.list = res.data.rows
      //   console.log('角色信息', res)
    },
    async getlist(id) {
      this.id = id
      const res = await sysUserGit(id)
      this.checkList = res.data.roleIds
      //   console.log('角色详情', res)
    },
    async submit() {
      await sysUserAssignRoles({
        id: this.id,
        roleIds: this.checkList
      })
      this.$message.success('修改成功')
      this.isShow = false
    }
  }
}
</script>

<style></style>
